package com.nolydake.swingnote.gui.ext.fordertree;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;

public class ForderTreePopup extends JPopupMenu implements ActionListener {

    private static final String OPERATOR_ADD_FORDER = "addForder";
    private static final String OPERATOR_DELETE_FORDER = "delForder";

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 2849988654729839835L;

    private ForderTree forderTree = null;

    public ForderTreePopup(ForderTree forderTree) {
        super();
        this.forderTree = forderTree;

        initGui();
    }

    private void initGui() {

        JMenuItem item = null;
        JMenu popMenu = new JMenu("新建");
        //
        item = new JMenuItem("文件夹");
        item.setActionCommand(OPERATOR_ADD_FORDER);
        item.addActionListener(this);
        popMenu.add(item);

        //
        item = new JMenuItem("笔记");
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "增加笔记");
            }
        });
        popMenu.add(item);

        this.add(popMenu);
        this.addSeparator();
        ///////////////////////

        this.add(new JMenuItem("重命名"));

        item = new JMenuItem("删除");
        item.setActionCommand(OPERATOR_DELETE_FORDER);
        item.addActionListener(this);
        this.add(item);

        this.add(new JMenuItem("移动"));
    }

    public void actionPerformed(ActionEvent e) {
        if (OPERATOR_ADD_FORDER.equals(e.getActionCommand())) {
            forderTree.addForder();
        }
        if (OPERATOR_DELETE_FORDER.equals(e.getActionCommand())) {
            forderTree.delForder();
        }
    }
}
